package com.jinlong.controller;

import com.jinlong.base.controller.BaseController;
import com.jinlong.constants.BaseApiConstants;
import com.jinlong.entity.UserEntity;
import com.jinlong.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class RegistController extends BaseController {

    private static final String LOCAREGIST= "locaRegist";

    private static final String LOGIN= "login";

    @Autowired
    private UserFeign userFeign;

    @RequestMapping("/locaRegist")
    public String locaRegist(){

        return LOCAREGIST ;
    }

    /*@RequestMapping("/login")
    public String login(){

        return LOGIN ;
    }*/
    @RequestMapping("/regist")
    public String regist(UserEntity userEntity, HttpServletRequest request){
        try{
            Map<String, Object> registMap = userFeign.regist(userEntity);
            Integer code = (Integer) registMap.get(BaseApiConstants.HTTP_CODE_NAME);
            if(!code.equals(BaseApiConstants.HTTP_200_CODE)){
                String msg = (String)registMap.get("msg");
               return setError(request,msg,LOCAREGIST);
            }
         return LOGIN;
        }catch (Exception e){

            return setError(request,"注册失败",LOCAREGIST);
            //e.printStackTrace();
        }

    }


}
